# -*- coding:utf-8 -*-
import copy
import threading
import pathlib

ABSPATH = pathlib.Path(__file__).resolve().parent.parent

_init_case_data = {"cases": []}


class DB:
    instance = None
    lock = threading.RLock()

    actions_status = {
        "hide_action": True,
        "show_action": False,
        "start_record_action": True,
        "pause_action": False,
        "continue_record_action": False,
        "stop_record_action": False,
        "config_action": True,
        "remote_action": True,
        "stop_remote_action": False,
        "quit_action": True,
    }

    ABSPATH = ABSPATH
    # 用例存储目录
    DirName = "testcases"
    # 用例任务目录（目前用来存储图片）
    case_task_name = ""

    # 是否在录制
    isRecord = False

    # 按钮给过来的录制状态,Start
    recordStatus = ''
    # 鼠标和键盘点击时的时间
    pressTime = None
    # 判断是否单机，双击，三击，拖动
    beforePressed = {}
    # 键盘按下记录
    beforeKeyPressed = {}
    # 用例数据
    caseData = {}

    isDrag = False

    # 在侧边栏选中的任务名称
    current_case_task_name = ''

    def __new__(cls, *args, **kwargs):
        if cls.instance:
            return cls.instance

        with cls.lock:
            cls.instance = object.__new__(cls)
            return cls.instance

    @classmethod
    def start_record(cls):
        cls.isRecord = True
        cls.caseData = copy.deepcopy(_init_case_data)

    @classmethod
    def stop_record(cls):
        cls.isRecord = False

        # cls.caseData = copy.deepcopy(_init_case_data)
